//
//  CertificateManagerVC.m
//  GasBusiness
//
//  Created by zfc on 2021/8/1.
//

#import "CertificateManagerVC.h"
#import "CertificateManagerCell.h"
@interface CertificateManagerVC ()

@end

@implementation CertificateManagerVC

- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationItem.title = @"证书管理";
    [self configTableView];
}


- (void)fetchData {
    NSString *url = @"/tiny-shop/v1/common/licenses/index";
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"page"] = @(self.page);
    [[NetWorksTools shared] requestWithMethod:GET url:url params:params successBlock:^(NSDictionary * _Nonnull response) {
        [self endRefresh];
        NSArray *arr = response[@"data"];
        if (self.page == 1) {
            [self.dataList removeAllObjects];
        } else {
            if (arr.count == 0) {
                self.page = self.page - 1;
                [self.tableView.mj_footer endRefreshingWithNoMoreData];
            }
        }
        [self.dataList addObjectsFromArray:arr];
        [self.tableView reloadData];
    } failureBlock:^(NSError * _Nonnull error) {

    }];
}

- (void) configTableView {
    self.isRemoveHeader = YES;
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.trailing.equalTo(self.view);
        make.bottom.equalTo(self.view).offset(-kBottomWhiteHeight);
    }];
    [self.tableView registerClass:[CertificateManagerCell class] forCellReuseIdentifier:@"CertificateManagerCell"];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSDictionary *dic = self.dataList[indexPath.row];
    CertificateManagerCell *cell  = [tableView dequeueReusableCellWithIdentifier:@"CertificateManagerCell"];
    cell.dic = dic;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 136;
}


@end
